package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ShoppingCartMapper {

    ShoppingCart findByShoppingCart(ShoppingCart shoppingCart);
    //跟新数量
    @Update("update shopping_cart set number=#{number} where id=#{id}")
    Integer updateNumber(@Param("id") Long id,@Param("number") Integer numBER);

    //插入新的购物数据
    @Insert("insert into shopping_cart value(null,#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor}," +
            "#{number},#{amount},#{createTime})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    Integer save(ShoppingCart shoppingCart);

    //查询指定用户购物车的集合数据
    @Select("select *from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> findAllByUserId(Long userId);

    //删除指定用户购物车数据
    @Delete("delete  from shopping_cart where user_id=#{userId}")
    Integer deleteByUserId(Long userId);
}
